package com.ruoyi.oa.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.oa.domain.OaAdminBorrow;
import com.ruoyi.oa.domain.vo.OaAdminBorrowVo;
import com.ruoyi.oa.domain.bo.OaAdminBorrowBo;
import com.ruoyi.oa.service.IOaAdminBorrowService;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.oa.domain.vo.OaProjectVo;


/**
 * 资料借阅申请
 *
 * @author ruoyi
 * @date 2023-08-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/adminBorrow")
public class OaAdminBorrowController extends BaseController {

    private final IOaAdminBorrowService iOaAdminBorrowService;

    /**
     * 查询资料借阅申请列表
     */
//    @SaCheckPermission("oa:adminBorrow:list")
    @GetMapping("/list")
    public TableDataInfo<OaAdminBorrowVo> list(OaAdminBorrowBo bo, PageQuery pageQuery) {
        return iOaAdminBorrowService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出资料借阅申请列表
     */
//    @SaCheckPermission("oa:adminBorrow:export")
    @Log(title = "资料借阅申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaAdminBorrowBo bo, HttpServletResponse response) {
        List<OaAdminBorrowVo> list = iOaAdminBorrowService.queryList(bo);
        ExcelUtil.exportExcel(list, "资料借阅申请", OaAdminBorrowVo.class, response);
    }

    /**
     * 获取资料借阅申请详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("oa:adminBorrow:query")
    @GetMapping("/{id}")
    public R<OaAdminBorrowVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iOaAdminBorrowService.queryById(id));
    }

    /**
     * 新增资料借阅申请
     */
//    @SaCheckPermission("oa:adminBorrow:add")
    @Log(title = "资料借阅申请", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<OaAdminBorrowBo> add(@Validated(AddGroup.class) @RequestBody OaAdminBorrowBo bo) {
        return R.ok(iOaAdminBorrowService.insertByBo(bo));
    }

    /**
     * 修改资料借阅申请
     */
//    @SaCheckPermission("oa:adminBorrow:edit")
    @Log(title = "资料借阅申请", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<OaAdminBorrow> edit(@Validated(EditGroup.class) @RequestBody OaAdminBorrowBo bo) {
        return R.ok(iOaAdminBorrowService.updateByBo(bo));
    }

    /**
     * 删除资料借阅申请
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("oa:adminBorrow:remove")
    @Log(title = "资料借阅申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iOaAdminBorrowService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
